package com.hnkywl.sts.action.sys;

import com.hnkywl.sts.entity.organ.Gsjg;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.entity.sys.Gw;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.sys.GwpzService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Melody_for_love
 * Date: 13-7-15
 * Time: 下午3:18
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/sys/gwpz")
public class GwpzAction extends SimpleActionSupport {
    private GwpzService gwpzService;
    //公司机构ID
    private Long gsjgId;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows = 10;
    //岗位ID
    private Long gwId;
    //岗位实体
    private Gw gw;

    //功能操作
    private List<Gncz> gnczList;
    private GnczService gnczService;

    private Gsjg gsjg;

//    @Action("gwpz")
//    public String yg() {
//        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
//        return SUCCESS;
//    }

    //岗位配置的查询分页显示
    @Action("gwpzList")
    public void gwpzList() {
        this.renderJson(this.gwpzService.findAllGsjgGw(gsjgId, page, rows));
    }

    @Action("gwpzAllList")
    public void gwpzAllList() {
        this.renderJson(this.gwpzService.findAllGsjgGw(gsjgId, 0, -1));
    }

    @Action("gwSearchList")
    public void gwSearchList() {
        this.renderJson(this.gwpzService.findAllGsjgGwSearch(page, rows));
    }

    @Action("gwpz_content")
    public String gwpzContent() {
        return SUCCESS;
    }

    //添加岗位配置
    @Action("add_gwpz")
    public void addGwpz() {
        try {
            this.gwpzService.saveGwpz(gsjg,gsjgId);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加岗位配置成功!\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    //删除岗位配置
    @Action("delete_gwpz")
    public void deleteGwpz() {
        try {
            this.gwpzService.deleteGwpz(gwId,gsjgId);
            renderJson("{\"statusCode\":\"200\", \"message\":\"删除岗位配置成功!\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

     //============getter and setter=========
    public Long getGsjgId() {
        return gsjgId;
    }

    public void setGsjgId(Long gsjgId) {
        this.gsjgId = gsjgId;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public Gsjg getGsjg() {
        return gsjg;
    }

    public void setGsjg(Gsjg gsjg) {
        this.gsjg = gsjg;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Long getGwId() {
        return gwId;
    }

    public void setGwId(Long gwId) {
        this.gwId = gwId;
    }

    public Gw getGw() {
        return gw;
    }

    public void setGw(Gw gw) {
        this.gw = gw;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    @Autowired
    public void setGwpzService(GwpzService gwpzService) {
        this.gwpzService = gwpzService;
    }

    @Autowired
    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }
}
